package com.wicket.mcp.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.wicket.mcp.service.SQLQueryService;
import io.modelcontextprotocol.server.transport.WebMvcSseServerTransportProvider;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.function.RouterFunction;

@Configuration
class McpConfig {
    @Bean
    WebMvcSseServerTransportProvider webMvcSseServerTransportProvider(ObjectMapper mapper) {
        return new WebMvcSseServerTransportProvider(mapper, "/mcp/message");
    }

    @Bean
    RouterFunction<?> mcpRouterFunction(WebMvcSseServerTransportProvider transportProvider) {
        return transportProvider.getRouterFunction();
    }

    @Bean
    ToolCallbackProvider jdbcQueryTools(SQLQueryService sqlQueryService) {
        return MethodToolCallbackProvider
                .builder()
                .toolObjects(sqlQueryService)
                .build();
    }
}
